﻿using Xamarin.Forms;
using Android.App;
using Android.Content.PM;
using Android.OS;
using Xamarin.Forms.Platform.Android;
using ImageCircle.Forms.Plugin.Droid;
using Moven.Droid.Gestures;
using Android.Views;
using Moven.Gestures;

namespace Moven.Droid
{
    [Activity (Label = "墨文",
        Theme= "@style/MyTheme",
        ScreenOrientation = ScreenOrientation.Portrait,
        ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
	public class MainActivity : FormsAppCompatActivity
    {
		GestureTouchDispatcher _gestureTouchDispatcher;

		protected override void OnCreate (Bundle bundle)
		{
            ToolbarResource = Resource.Layout.toolbar;
            TabLayoutResource = Resource.Layout.tabs;
            base.OnCreate (bundle);

			_gestureTouchDispatcher = new GestureTouchDispatcher(this);
			GestureRecognizerExtensions.Factory = new NativeGestureRecognizerFactory();

			Forms.Init (this, bundle);
			ImageCircleRenderer.Init();
			LoadApplication (new App());
		}

		public override void OnBackPressed()
		{
			var app = (App)Xamarin.Forms.Application.Current;
			if (app.CanGoBack)
			{
				base.OnBackPressed();
				if (app.IsRootPage)
				{
					Java.Lang.JavaSystem.Exit(0);
				}
			}
		}

		public override bool DispatchTouchEvent(MotionEvent ev)
		{
			_gestureTouchDispatcher.DispatchTouchEvent(ev);
			return base.DispatchTouchEvent(ev);
		}
	}
}

